import { Component, OnInit, Output, EventEmitter } from '@angular/core';
import { RemoveTableService } from '../../public/serve/remove-table/remove-table.service';
import { HintsService } from '../../public/serve/hints/hints.service';
import {Service} from '../../server/server';
declare var $:any;
@Component({
  selector: 'app-internal-indexed-delete',
  templateUrl: './internal-indexed-delete.component.html',
  styleUrls: ['./internal-indexed-delete.component.css']
})
export class InternalIndexedDeleteComponent implements OnInit {

  ids : any;
  deleteId : any;
  deleteSid : any;
  public internalDeleteThemeIdEmit: any;
  constructor(
      public server: Service,
    public removeTableService: RemoveTableService,
    private hintsService: HintsService
  ) { }

  ngOnInit() {
      this.internalDeleteThemeIdEmit = this.server.internalDeleteThemeIdEmit.subscribe((value: any) => {
          if (value) {
            if(String(value).indexOf(',')  !== -1){
                this.deleteId = String(value).split(',')[0];
                this.deleteSid = String(value).split(',')[1];
            }else{
                this.deleteId = value;
            }
          }
      });
  }

  ngOnDestroy() {
    this.internalDeleteThemeIdEmit ? this.internalDeleteThemeIdEmit.unsubscribe() : '';
  }

  /**
   * 删除
   */
  _delete(){
    this.removeTableService
    .confirmRemove('ids',this.server.baseUrl + 'Service/IdxProduct/delProductThemeWords','token','b25dbd7138cf48e09941087e6d9a2e93')
    .then(res => {
      if(res.result_code == '0000'){
          this.server.internalDeleteContentsEmit.emit(this.deleteId+','+this.deleteSid);
          this.server.internalindexeddeleteentEmit.emit(true);
      }

      this.hintsService.messages(res.message,res.result_code);
      return;
    })
    .catch(err => {
      this.hintsService.messages('error','error');
      return;
    });
  }

  /**
   * 删除
   */
  _deleteRel(){

    this.removeTableService
    .confirmRemove('ids',this.server.baseUrl + 'Service/IdxProduct/delProductThemeWords','token','b25dbd7138cf48e09941087e6d9a2e93')
    .then(res => {
      if(res.result_code == '0000'){
          this.server.internalindexeddeleteentEmit.emit(true);
      }

      this.hintsService.messages(res.message,res.result_code);
      return;
    })
    .catch(err => {
      this.hintsService.messages('error','error');
      return;
    });
  }

}
